<?php defined('SYSPATH') or die('No direct script access.');

class Controller_Admin_Category extends Controller_DefaultTemplate{

public function action_index()
{
}

public function action_list()
{
	$category = ORM::factory('category')->find_all();
	$this->template->content = View::factory('book/category_list');
	$this->template->content->set('category_list', $category->as_array());
}

public function action_save()
{
	if ($_POST)
    {
		$category = ORM::factory('category');
		$category->values(array(
			'name' => arr::get($_POST, 'name'),
		));
		$category->save();
		$this->request->redirect('/admin/category/list/');
		return;
	}
	echo 'fail';
}

public function action_delete()
{
	$id = $this->request->param('id');
	if ($id)
    {
		$category = ORM::factory('category')->where('id', '=', $id)->find();
		if ($category->loaded())
		{
			$category->delete();
		}
		$this->request->redirect('/admin/category/list/');
	}
}

}


